<?php

// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;

use OT\DataDictionary;

/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class IndexController extends HomeController {



    public function _initialize() {
        //網站設置
        $config = D('Document')->lists(81);
        $configs = D('Document')->detail($config[0]['id']);
        $this->assign('config', $configs);
    }

    //系统首页
    public function index() {

        if(isset($_GET['cate'])){
            $this->assign('cates',$_GET['cate']);
        }
        //標題
        $menu = D('Category')->getMenu();
        $this->assign("menu", $menu);
        $p = 1;

        //首頁推薦
        $variety = D('Document')->lists(35);
        foreach ($variety as $ks=>$vs){
            $varietys[]=D('Document')->detail($vs['id']);
        }
        $this->assign('variety', $varietys);

        $disImages = D('Document')->variety(10);
        $logo = D('Document')->lists(80); //logo         
        $logos = D('Document')->detail($logo[0]['id']);
        $this->assign('logo', $logos);

        // 艺人管理    
        $rImages = D('Document')->lists(66);
        foreach ($rImages as $key => $value) {
            $rImage[] = D('Document')->detail($value['id']);
        }

        $this->assign('rImages1', $rImage);

        //活动策划 
        $eImages = D('Document')->lists(68);
        foreach ($eImages as $k => $v) {
            $eImage[] = D('Document')->detail($v['id']);
        }
        $this->assign('eImages', $eImage);
        //市场推广
        $mImages = D('Document')->lists(83);
        foreach ($mImages as $k1 => $v1) {
            $mImage[] = D('Document')->detail($v1['id']);
        }
        $this->assign('mImages', array_slice($mImage, 0, 4));

        //合作客户
        $cImages = D('Document')->lists(40);
        $cImage = D('Document')->detail($cImages[0]['id']);
        $this->assign('cImages', $cImage);

        //影音製作
        $vedio=D('Document')->lists(70);        
        $vedios=  array_slice($vedio, 0,2);
        foreach ($vedios as $ks=>$vs){
            $vedioss[]=D('Document')->detail($vs['id']);
        }
        $this->assign('vedio',$vedioss);        

        //藝人管理簡介
        $artistintro = D('Document')->lists(65);
        $artistintros = D('Document')->detail($artistintro[0]['id']);
        $this->assign('artistintro', $artistintros);

        //活動策劃簡介
        $planintro = D('Document')->lists(67);
        $planintros = D('Document')->detail($planintro[0]['id']);
        $this->assign('planintro', $planintros);


        //影音製作簡介
        $videointro = D('Document')->lists(69);
        $videointros = D('Document')->detail($videointro[0]['id']);
        $this->assign('videointro', $videointros);

        //市場推廣簡介
        $marketintro = D('Document')->lists(82);
        $marketintros = D('Document')->detail($marketintro[0]['id']);
        $this->assign('marketintro', $marketintros);

        //關於贊娛樂
        $about = D('Document')->lists(84);
        $abouts = D('Document')->detail($about[0]['id']);
        $this->assign('about', $abouts);

        $this->display();
    }

    //联系我们
    public function feedback() {
        $data = array();
        $data['title'] = $_POST['contacts'];
        $data['uname'] = $data['title'];
        $data['phone'] = $_POST['phone'];
        $data['email'] = $_POST['email'];
        $data['content'] = $_POST['content'];
        if ($data['title'] == '' || $data['phone'] == '' || $data['email'] == '' || $data['content'] == '') {
            $this->error('请输入完整信息');
        }
        $data['category_id'] = $_GET['category_id'];
        $data['pid'] = $_GET['pid'];
        $data['model_id'] = $_GET['model_id'];
        $data['status'] = 1;
        $data['create_time'] = time();
        $data['update_time'] = time();
        $data['type'] = 2;
        $res = D('Document')->updatefeedback($data);
        if (!$res) {
            $this->error(D('Document')->getError());
        } else {
            if (D('Email')->send_mail('', '', '')) {
                $this->success($res['id'] ? '更新成功' : '發表成功，已通知商家', Cookie('__forward__'));
            } else {
                $this->error('通知商家失敗');
            }
        }
    }

   

}
